package barrage

import (
	"game_server/entity"
	"game_server/framework/global"

	"github.com/spf13/viper"
)

var isMigrated bool

func Migrate() {
	if isMigrated {
		return
	}
	global.MysqlClient.AutoMigrate(&entity.BarrageEntity{})
	isMigrated = true
}

func QueryAll() []entity.BarrageEntity {
	Migrate()
	var result []entity.BarrageEntity
	gameType := viper.GetInt("environment.game-type")
	global.MysqlClient.Where("game_type = ?", gameType).Find(&result)
	return result
}
